package com.caizi.socket.normal;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class EchoServer {

    public void acceptor() throws IOException {
        ServerSocket server = null;
        while (true) {
            server = new ServerSocket(1111);
            Socket accept = server.accept();
            OutputStream outputStream = accept.getOutputStream();
            PrintWriter pw = new PrintWriter(outputStream, true);
            InputStream inputStream = accept.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
            String msg = null;
            while ((msg = br.readLine()) != null) {
                System.out.println(msg);
                pw.println(msg + "回答");
            }
        }
    }

    public static void main(String[] args) throws IOException {
        new EchoServer().acceptor();
    }
}
